package internal

import (
	"fmt"
	"slices"
)

func SelectionSort(list []int) []int {
	if len(list) == 0 {
		return list
	}

	result := make([]int, 0, len(list))
	for len(list) > 0 {
		fmt.Println(list)
		max := list[0]
		index := 0
		for i, v := range list {
			if v > max {
				max = v
				index = i
			}
		}
		result = append(result, max)
		if index == len(list)-1 {
			list = list[:index]
		} else {
			// list = append(list[:index], list[index+1:]...)
			// 有新的内置库了。代码更优雅，但还是老问题，语法糖导致新手的学习难度上升
			list = slices.Delete(list, index, index+1)
		}
	}

	return result
}
